﻿using System;
using System.Collections.Generic;
using System.Text;
using ArgusLib.Zip;
using System.IO;
using System.Drawing;

namespace ArgusLib.BugReport
{
	public delegate void AddCrashInfoHandler(AddCrashInfoArgs e);
	public delegate void CrashDetectedHandler(CrashDetectedArgs e);
	public delegate void CrashHandler(CrashArgs e);

	public class AddCrashInfoArgs : EventArgs
	{
		ZipFile zipFile;

		public AddCrashInfoArgs(ZipFile zipFile)
		{
			this.zipFile = zipFile;
		}

		public ICollection<string> Entries { get { return this.zipFile.EntryFileNames; } }

		public void Add(string entryName, WriteDelegate writeDelegate)
		{
			if (string.IsNullOrEmpty(entryName) == false)
				throw new ArgumentNullException("entryName");
			if (writeDelegate == null)
				throw new ArgumentNullException("writeDelegate");

			string newEntryName = entryName;
			string ext = System.IO.Path.GetExtension(entryName);
			entryName = System.IO.Path.GetFileNameWithoutExtension(entryName);
			for (int i = 1; i < int.MaxValue; i++)
			{
				if (zipFile.ContainsEntry(newEntryName) == false)
					break;

				newEntryName = string.Format("{0} ({1}){2}", entryName, i, ext);
			}
			this.zipFile.AddEntry(newEntryName, writeDelegate);
		}
	}

	public class CrashDetectedArgs : EventArgs
	{
		public FileInfo CrashInfoFile { get; private set; }
		public ExceptionInfo Exception { get; private set; }
		public Image[] Screenshots { get; private set; }
		public IProtocol Protocol { get; set; }

		public CrashDetectedArgs(FileInfo crashInfoFile, ExceptionInfo exception, Image[] screenshots)
		{
			this.CrashInfoFile = crashInfoFile;
			this.Exception = exception;
			this.Screenshots = screenshots;
			this.Protocol = null;
		}
	}

	public class CrashArgs : EventArgs
	{
		public Exception Exception{get;private set;}

		public CrashArgs(Exception exception)
		{
			this.Exception = exception;
		}
	}
}
